package com.dotstone.chipism.ui.login.model.impl;


import android.util.Log;

import com.dotstone.chipism.api.ApiService;
import com.dotstone.chipism.client.RetrofitClient;
import com.dotstone.chipism.ui.login.bean.request.LoginRequestBean;
import com.dotstone.chipism.ui.login.model.LogInModel;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import io.reactivex.Observable;
import io.reactivex.functions.Function;

/**
 * Created by lvr on 2017/5/19.
 */

public class LogInModelImpl implements LogInModel {
    @Override
    public Observable<String> loadLogIn(String username, String password) {
        Log.i("登录", "开始333登录" + username + "---" + password);
        ApiService api = RetrofitClient.getInstance().create(ApiService.class);
        Log.i("登录", "开始555登录" + username + "---" + password);
        LoginRequestBean loginBean = new LoginRequestBean("10000" ,  username,password , "未知" ,"3" , ""+System.currentTimeMillis());
        String content = new Gson().toJson(loginBean, new TypeToken<LoginRequestBean>(){}.getType());//把JSON格式的字符串转为List
        Log.i("登录", "开始666登录" + content);
        return api.getLogInResult(content).map(new Function<String, String>() {
            @Override
            public String apply(String bean) throws Exception {
                Log.i("登录" , "返回数据:" + bean);
                return "";
            }
        }).compose(RetrofitClient.schedulersTransformer);//线程调度;
    }
}
